package com.codingke.codingbookstore.utils;

import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.codingke.codingbookstore.App;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * descreption:
 * company: codingke.com
 * Created by vince on 15/10/13.
 */
public class AppUtils {

    //隐藏输入法
    public static void hideInputMethod(View view) {
        InputMethodManager imm = (InputMethodManager) App.context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm.isActive()) {
            imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

    static DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

    public static String getDate(Date date) {
        return df.format(date);
    }

    /**
     * 手机号隐藏中间4位
     *
     * @param mobile
     * @return
     */
    public static String formatPhoneNumber(String mobile) {
        StringBuilder maskNumber = new StringBuilder(11);
        maskNumber.append(mobile.substring(0, 3));
        maskNumber.append("****");
        maskNumber.append(mobile.substring(7, mobile.length()));
        return maskNumber.toString();
    }

    public static String getStatus(int statusCode) {

        String status = "";
        switch (statusCode) {
            case Constant.ORDER_NON_PAYMENT:
                status = "未付款";
                break;
            case Constant.ORDER_PAYMENTS_RECEIVED:
                status = "已付款";
                break;
            case Constant.ORDER_DELIVERED:
                status = "已发货";
                break;
            case Constant.ORDER_RECEIVED_GOODS:
                status = "已收货";
                break;
            case Constant.ORDER_HAS_BEEN_EVALUATED:
                status = "已评价";
                break;
            default:
                break;
        }
        return status;
    }

}
